<template>
    <Form
            :form-items="formItems"
            :init-data-url="$baseURL.base +  '/base/user/userinfo/current'"
            :handle-init-data="handleInitData"
            :submit-success="submitSuccess"
            style="width:500px;"
    ></Form>
</template>

<script>
    import Form from '../../../../common-util/src/components/page/Form.vue'
    export default {
        components:{
            Form
        },
        data (){
            return {
                formItems:[
                    {
                        field: {
                            name: 'avatar'
                        },
                        element:{
                            label: '头像',
                            type: 'upload',
                            upload: {
                                type: 'uploadInput',
                                accept: 'image/*'
                            },
                        }
                    },
                    {
                        field: {
                            name: 'nickname'
                        },
                        element:{
                            label: '昵称',
                            required: true
                        }
                    },
                    {
                        field: {
                            name: 'genderDictId'
                        },
                        element:{
                            label: '性别',
                            type: 'selectDict',
                            selectDict:{
                                groupCode:'gender'
                            },
                            required: true
                        }
                    },
                    {
                        element:{
                            type: 'button',
                            button:[
                                {
                                    action: 'submit',
                                    requestMethod:'put',
                                    url: this.$baseURL.base +  '/base/user/userinfo/current',
                                    label: '保存'
                                }
                            ]
                        }
                    }
                ]
            }
        },
        mounted(){
        },
        methods:{
            handleInitData (data){
                return data.user
            },
            submitSuccess(data,form){
                data.user.nickname = form.nickname
                if(form.avatar){
                    data.user.avatar = form.avatar
                }
                this.$bus.$emit('userinfoEdit',data)

            }
        }
    }
</script>

<style scoped>
    .item {
        margin-bottom: 18px;
    }
</style>